/**
 * AgaEngine (c)2011.
 * FileName:TileMapTool.java
 */
package aga.engine.tools;

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.BitmapFactory;

/**
 * 
 * @author zhe.yangz
 */
public class TileMapTool {
	//===========================================================
	//Constants
	//===========================================================

	//===========================================================
	//Fields
	//===========================================================

	//===========================================================
	//Constructors
	//===========================================================

	//===========================================================
	//Getter & Setter
	//===========================================================

	//===========================================================
	//Methods for/from SuperClass/Interfaces
	//===========================================================

	//===========================================================
	//Methods
	//===========================================================
	public static TileMap loadFromTileStudio(Context c, String mapName) throws IOException {
		TileMap tmap = new TileMap();
		
		InputStream is = c.getAssets().open(mapName + ".map");
		int v = -1, x = 0, y = 0;
		while ( (v = is.read()) != -1) {
			tmap.map[x][y] = v;
			if (x < tmap.map.length-1) x++;
			else { x = 0; y++; }
		}
		is.close();
		
		is = c.getAssets().open(mapName + ".bg.png");
		tmap.png = BitmapFactory.decodeStream(is);
		is.close();
		
		is = c.getAssets().open(mapName + ".tileset.png");
		tmap.tileset = BitmapFactory.decodeStream(is);
		is.close();
		
		return tmap;
	}
	//===========================================================
	//Inner and Anonymous Classes
	//===========================================================
}
